/**
 * json 转化器，将返回的对象转为json 字符串进行输出
 * 接口必备中间件
 * @returns {Function}
 */
module.exports = () => {
    async function render(json) {
        this.set("Content-Type", "application/json");
        this.body = await JSON.stringify(json);
    }

    return async (ctx, next) => {
        ctx.json = await render.bind(ctx);
        await next();
    }
};
